"""
Swagger UI 视图配置
"""
from django.http import HttpResponse
from django.views.decorators.http import require_http_methods
import os


@require_http_methods(["GET"])
def swagger_ui_view(request):
    """
    提供Swagger UI界面
    """
    # 读取HTML文件
    html_file_path = os.path.join(os.path.dirname(__file__), 'swagger_ui.html')
    
    try:
        with open(html_file_path, 'r', encoding='utf-8') as f:
            html_content = f.read()
        return HttpResponse(html_content, content_type='text/html')
    except FileNotFoundError:
        return HttpResponse("Swagger UI文件未找到", status=404)


@require_http_methods(["GET"])
def swagger_docs_view(request):
    """
    提供Swagger YAML文档
    """
    # 读取YAML文件
    yaml_file_path = os.path.join(os.path.dirname(__file__), 'swagger.yaml')
    
    try:
        with open(yaml_file_path, 'r', encoding='utf-8') as f:
            yaml_content = f.read()
        return HttpResponse(yaml_content, content_type='text/yaml')
    except FileNotFoundError:
        return HttpResponse("Swagger文档文件未找到", status=404)